const request = require("../../utils/request")
const api = require("../../config/api")
const { shareOptions } = require("../../utils/access")
const { jump } = require("../../utils/utils")
const app = getApp()

// pages/residenceCertificationExplain/residenceCertificationExplain.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 是否显示去认证
    show: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      show: Boolean(options?.show)
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAuthStatus()
  },

  /**
   * 跳转去认证
   */
  async jumpAuth() {
		if (app.isLogin()) {
      jump('residenceCertification')
		} else {
			await app.login()
		}
  },
  // 获取用户认证状态 0未认证 1已认证 2审认证核中
  async getAuthStatus(){
    const res = await request.get(api.getAuthStatus, null, { loading: false, modal: false })
    if (res.httpStatus === 200) {
      this.setData({
        show: res.data.authenticationStatus === 0,
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    return shareOptions('default', e)
  }
})